<?php
session_start();
if (!$_SERVER['HTTPS']) {
	Header( "HTTP/1.1 301 Moved Permanently" );
	Header('Location: https://'.$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]);
}
abstract class user {
	const LOGIN_OK=true;
	const LOGIN_WRONG=false;
	public $name='anonymous';
	
	function login($user,$pass){
		if (self::check_credentials($user,$pass)) {
			$arr=array();
			$arr['username']=$user;
			$arr['secret']=md5(rand(1,1024));
			dbengine::set_array('logged_users',$arr);
			$_SESSION['logged']='ok';
			return true;
		} else {
			return false;
		}
	}
	function logout(){
		session_destroy();
		Header( "HTTP/1.1 301 Moved Permanently" );
		Header('Location: auth_test.php');
	}
	function status(){
		if($_SESSION['logged']=='ok') {
			return true;
		} else {
			$_SESSION['logged']=='not ok';
			return false;
		}
	}
	private function check_credentials($user, $pass) {
		if (md5(dbengine::get_value('users',$user,'password'))==md5($pass)) {
			return self::LOGIN_OK;
			
		} else {
			
			return self::LOGIN_WRONG;
		}
	}
	
}
abstract class dbengine{
	function get_value($table,$key,$value){
		return 123;
	}
	function get_array($table,$key) {
		$arr=array('secret' => md5(123));
		return $arr;
	}
	function set_array($table,$arr) {
		
	}
}
?>